/**
 * Simple regex experiment to create an automatic emoticons by Taufik Nurrohman
 * Original: http://hompimpaalaihumgambreng.blogspot.com
 * Update: 03 Oktober 2012
 * modified by Panembahan Satyapradana www.klikedukasi.com
 */

$(function() {

	// Append an emoticon bar before comment-form
	if (putEmoAbove) {
		$(putEmoAbove).before('<div class="emoWrap"> :) ;) :( :yaya: :D =D ^_^ :nangis :terharu :udud :gila :heran :lieur *hore :love :marah X@ *mantap :-bd :bye :ceramah :* :berdoa :nohope :dolar :ehm :wouw :ganteng :genit :koding :malu :p :ngacir :ngakak *piss *belajar :salaman :hammer</div>');
	}
	function emo(emo, imgRep, emoKey) {
		$(emoRange).each(function() {
			$(this).html($(this).html()
			.replace(/<br>(:|;|=|\^)/g, "<br> $1")
			.replace(emo, " <img src='" + imgRep + "' class='emo delayLoad' alt='" + emoKey + "' />"));
		});
	}
	emo(/\s:\)+/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/smile.gif", ":)");
	emo(/\s;\)+/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/wink.gif", ";)");
	emo(/\s:\(/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/sadanimated.gif", ":(");
	emo(/\s:yaya:/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/yaya.gif", ":yaya:");
	emo(/\s:D/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/haha.gif", ":D");
	emo(/\s=D/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/hihi.gif", "=D");
	emo(/\s\^(\_|)\^/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/senyum-tulus.gif", "^_^");
	emo(/\s:nangis/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/cry.gif", ":nangis");
	emo(/\s:terharu/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/tears.gif", ":terharu");
	emo(/\s:udud/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/smoking.gif", ":udud");
	emo(/\s:gila/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/crazy.gif", ":gila");
	emo(/\s:heran/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/conf.gif", ":heran");
	emo(/\s:lieur/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/lieur.gif", ":lieur");
	emo(/\s*hore/ig, "https://str4sh-project.googlecode.com/svn/trunk/smileys/applause.gif", "*hore");
	emo(/\s:love/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/love.gif", ":love");
	emo(/\s:marah/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/marahbesar.gif", ":marah");
	emo(/\s\X\@/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/arrgh.gif", "X@");
	emo(/\s\*mantap/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/top.gif", "*mantap");
	emo(/\s:-bd/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/topmarkotop.gif", ":-bd");
	emo(/\s:bye/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/bye.gif", ":bye");
	emo(/\s:ceramah/g, "http://str4sh-project.googlecode.com/svn/trunk/smileys/explain.gif", ":ceramah");
	emo(/\s:\*/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/cium.gif", ":*");
	emo(/\s:berdoa/ig, "https://str4sh-project.googlecode.com/svn/trunk/smileys/berdoa.gif", ":berdoa");
	emo(/\s:nohope/ig, "https://str4sh-project.googlecode.com/svn/trunk/smileys/capedeh.gif", ":nohope");
	emo(/\s:dolar/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/dolar.gif", ":dolar");
	emo(/\s:ehm/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/ehm.gif", ":ehm");
	emo(/\s:wouw/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/eyepopping.gif", ":wouw");
	emo(/\s:ganteng/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/ganteng.gif", ":ganteng");
	emo(/\s:genit/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/genit.gif", ":genit");
	emo(/\s:koding/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/koding.gif", ":koding");
	emo(/\s:malu/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/malu.gif", ":malu");
	emo(/\s:p/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/melet.gif", ":p");
	emo(/\s:ngacir/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/ngacirs.gif", ":ngacir");
	emo(/\s:ngakak/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/ngakak.gif", ":ngakak");
	emo(/\s\*piss/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/piss.gif", "*piss");
	emo(/\s\*belajar/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/read.gif", "*belajar");
	emo(/\s\:salaman/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/sepakat.gif", ":salaman");
	emo(/\s\:hammer/ig, "http://str4sh-project.googlecode.com/svn/trunk/smileys/stupidme2.gif", ":hammer");
	
	// Show alert one times!
	$('.emoWrap').one("click", function() {
		if(emoMessage) {
			alert(emoMessage);
		}
	});
	// Click to show the code!
	$('.emo').css('cursor', 'pointer').live("click", function(e) {
		$('.emoKey').remove();
		$(this).after('<input class="emoKey" type="text" size="6" value=" ' + this.alt + '" />');
		$('.emoKey').trigger("select");
		e.stopPropagation();
	});
	$(document).on("click", function() {
		$('.emoKey').remove();
	});

});